<h2><%= sprintf('%s', $model->isNewRecord ? 'Cadastrar usuário' : 'Editar usuário'); %></h2>

<div class="form">

    <%
        $form = $this->beginWidget('CActiveForm', array(
            'id' => 'usuario-form',
            'enableClientValidation' => true
        ));
    %>

	<p class="note">Campos com <span class="required">*</span> são de preenchimento obrigatório</p>

	<%= $form->errorSummary($model, "Por favor corrija os seguintes erros:"); %>

	<div class="row">
		<%=
             $form->labelEx($model, 'email') .
		     $form->textField($model, 'email', array('maxlength' => 128 )) .
		     $form->error($model, 'email');
        %>
	</div>

	<div class="row">
		<%=
             $form->labelEx($model, 'senha') .
		     $form->passwordField($model, 'senha', array('minlength' => 6, 'maxlength' => 32)) .
		     $form->error($model, 'senha');
        %>
	</div>

	<div class="row">
		<%=
             $form->labelEx($model, 'confirmarSenha') .
		     $form->passwordField($model, 'confirmarSenha', array('minlength' => 6, 'maxlength' => 32)) .
		     $form->error($model, 'confirmarSenha');
        %>
	</div>
        
	<div class="row">
		<%=
             $form->labelEx($model, 'nome_completo') .
		     $form->textField($model, 'nome_completo', array('maxlength' => 128)) .
		     $form->error($model, 'nome_completo');
        %>
	</div>

	<div class="row">
		<%=
             $form->labelEx($model, 'perfil') .
             $form->dropDownList($model, 'perfil',
                array('Administrador' => 'Administrador',
                      'Operador' => 'Operador',
                       'Visitante' => 'Visitante'),
                array('prompt' => 'Selecione um perfil', 'class' => 'select_perfil')) .
             $form->error($model, 'perfil');
        %>
	</div>
        <div id="div_operator" class="<%= sprintf('%s', $model->perfil == 'Operador' ? '' : 'none'); %>">
            <div class="row">
                <%=
                     $form->labelEx($model, 'centro_de_operacao') .
                     $form->textField($model, 'centro_de_operacao', array('maxlength' => 32)) .
                     $form->error($model, 'centro_de_operacao');
                %>
            </div>

            <div class="row">
                <%=
                     $form->labelEx($model, 'orgao') .
                     $form->textField($model, 'orgao', array('maxlength' => 32)) .
                     $form->error($model, 'orgao');
                %>
            </div>

            <div class="row">
                <%=
                     $form->labelEx($model, 'email_responsavel_orgao') .
                     $form->textField($model, 'email_responsavel_orgao', array('maxlength' => 128)) .
                     $form->error($model, 'email_responsavel_orgao');
                %>
            </div>

            <div class="row">
                <%=
                     $form->labelEx($model, 'telefone_responsavel_orgao') .
                     $form->textField($model, 'telefone_responsavel_orgao', array('maxlength' => 16)) .
                     $form->error($model, 'telefone_responsavel_orgao');
                %>
            </div>
        </div>
	<div class="row">
		<%=
             $form->labelEx($model, 'outras_informacoes') .
             $form->textArea($model, 'outras_informacoes', array('maxlength' => 128, 'rows' => 3)) .
             $form->error($model, 'outras_informacoes');
        %>
	</div>

	<div class="row buttons">
		<%= CHtml::submitButton($model->isNewRecord ? 'Cadastrar usuário' : 'Atualizar usuário'); %>
	</div>
	
<% $this->endWidget(); %>

</div><!-- form -->

<%
    Yii::app()->clientScript->registerScript('div_operator', "
        $('.select_perfil').change(function() {
            if($(this).find('option:selected').text() == 'Operador')
                $('#div_operator').fadeIn();
            else
                $('#div_operator').fadeOut();
        });
    ");
%>
